﻿using System;
using UnityEngine;

namespace RenderHeads.Media.AVProVideo.Demos
{
	// Token: 0x02000011 RID: 17
	public class StartEndPoint : MonoBehaviour
	{
		// Token: 0x0600004B RID: 75 RVA: 0x00003FAC File Offset: 0x000021AC
		private void OnEnable()
		{
			this._isStartQueued = true;
		}

		// Token: 0x0600004C RID: 76 RVA: 0x00003FB8 File Offset: 0x000021B8
		private void Update()
		{
			if (StartEndPoint.IsVideoLoaded(this._mediaPlayer))
			{
				if (this._isStartQueued)
				{
					StartEndPoint.DoStart(this._mediaPlayer, this._startPointSeconds);
					this._isStartQueued = false;
				}
				else if (!this._loop)
				{
					StartEndPoint.DoCheckEnd(this._mediaPlayer, this._endPointSeconds);
				}
				else
				{
					StartEndPoint.DoCheckLoop(this._mediaPlayer, this._endPointSeconds, this._startLoopSeconds);
				}
			}
		}

		// Token: 0x0600004D RID: 77 RVA: 0x00004038 File Offset: 0x00002238
		private static bool IsVideoLoaded(MediaPlayer mp)
		{
			return mp != null && mp.Control != null && mp.Control.HasMetaData();
		}

		// Token: 0x0600004E RID: 78 RVA: 0x00004060 File Offset: 0x00002260
		private static void DoStart(MediaPlayer mp, float positionSeconds)
		{
			mp.Control.Seek(positionSeconds * 1000f);
			mp.Play();
		}

		// Token: 0x0600004F RID: 79 RVA: 0x0000407C File Offset: 0x0000227C
		private static void DoCheckEnd(MediaPlayer mp, float positionSeconds)
		{
			if (mp.Control.IsPlaying() && mp.Control.GetCurrentTimeMs() >= positionSeconds * 1000f)
			{
				mp.Pause();
			}
		}

		// Token: 0x06000050 RID: 80 RVA: 0x000040AC File Offset: 0x000022AC
		private static void DoCheckLoop(MediaPlayer mp, float positionSeconds, float positionLoop)
		{
			if (mp.Control.IsPlaying() && mp.Control.GetCurrentTimeMs() >= positionSeconds * 1000f)
			{
				mp.Control.Seek(positionLoop * 1000f);
			}
		}

		// Token: 0x0400003F RID: 63
		public MediaPlayer _mediaPlayer;

		// Token: 0x04000040 RID: 64
		public float _startPointSeconds;

		// Token: 0x04000041 RID: 65
		public float _endPointSeconds;

		// Token: 0x04000042 RID: 66
		public bool _loop;

		// Token: 0x04000043 RID: 67
		[Tooltip("If looping is enabled, this is the time the video rewinds to when it reaches the end point")]
		public float _startLoopSeconds;

		// Token: 0x04000044 RID: 68
		private bool _isStartQueued;
	}
}
